home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc International / Recipes / Sharing TSM document < prev    next >
Encoding:
Text File  |  1996-11-14  |  5.7 KB  |  99 lines  |  [TEXT/ttxt]

  1. Sharing TSM document
  2. by The OpenDoc™ Design Team
  3. February 16, 1996
  4.  
  5.  
  6. © 1993-1996  Apple Computer, Inc. All Rights Reserved.
  7. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  8. Mac and OpenDoc are trademarks of Apple Computer, Inc.
  9.  
  10.  
  11. Introduction
  12.  
  13. The OpenDoc TSM Addition is a shared library based on CFM/CFM-68K.  It provides a solution to share a single TSM document data structure among all the parts in an OpenDoc document.  The input method which supports multi-session, such as Kotoeri, allocates 5 to 10 K byte  in the application heap area for every TSM document (TSM session).  A text editing part which is embedded in an OpenDoc document/container will be able to reduce application heap by sharing the TSM document.
  14.  
  15. It contains three functions  which replaces or changes the interface types and the refcon field of the TSM document structure.  The functions are for sharing a single TSM document, representing a Text Services Manager session, among all the parts in a single OpenDoc document. The library provides a new interface for accessing possibly a TSM Document to be shared.
  16.  
  17. This library will be installed with OpenDoc-J or a third party product.  It means there is no guarantee that the API in the library  is always available even if OpenDoc is installed.  Therefore, the OpenDoc part needs to import this library as ˙weak import˙ at the object linking process.  
  18.  
  19.  
  20. Application Program Interfaces
  21.  
  22. The shared library provides the following three APIs for OpenDoc part.
  23.  
  24. • ODNewTSMDocumentForPart
  25. The ODNewTSMDocumentForPart function creates a shared TSM document and returns a TSM document ID to be shared.  If  a single TSM document is being shared, the interface types and refcon of the shared TSM document are replaced and returned.  If there is no shared TSM document ID in the document process,  it creates a new TSM document with the interface type and refcon using NewTSMDocument and returns its TSM document ID as the shared one.  See also the NewTSMDocument function in InsideMacintosh: Text.
  26.  
  27. Pascal OSErr ODNewTSMDocumentForPart( short interfaceNum, OSType interfaceType[], TSMDocumentID *docID, long refcon)
  28.  
  29. interfaceNum is the number of text service interface types. Currently, this number must be 1.  
  30. interfaceType is a list of text service interface types. This list helps the Text Services Manager to locate the text services that have the correct interface type. Currently, the Text Services Manager has defined one interface type: kTextService ( = 'tsvc'). The caller can also set another interface type: kTSMTEInterfaceType ( = 'tmTE'), if the TSMTE is installed into your Extension folder.  The data type interfaceType is a simple array of 4-character (OSType) tags.  
  31. docID is a TSM document ID to be shared if the completion of the call is successful.  
  32. refCon is a reference constant to store in the TSM document record. It may have any value you wish.  If you pass kTSMTEInterfaceType to NewTSMDocument, this argument has a different meaning:  Instead of a value to be stored in the TSM document, you should pass in the address of a variable for TSMTERecHandle.
  33.  
  34. • ODUseTSMDocumentForPart
  35. The ODUseTSMDocumentForPart function changes the interface type of a TSM document in order to activate the sharing of the TSM document on your part. Your part has to call this function just before calling the function which takes the TSM document ID parameter such as ActivateTSMDocument() or ODDeleteTSMDocumentForPart().  The text edit part will have to call this before calling ActivateTSMDocument(), DeactivateTSMDocument(), FixTSMDocument(), or ODDeleteTSMDocumentForPart().
  36.  
  37. Pascal OSErr ODUseTSMDocumentForPart( short interfaceNum, OSType interfaceType[], TSMDocumentID docID, long refcon)
  38.  
  39. • ODDeleteTSMDocumentForPart
  40. The ODDeleteTSMDocumentForPart function closes opened text service components for the shared TSM document. If the TSM document is not shared with other parts, it is closed completely.
  41.  
  42. Pascal OSErr ODDeleteTSMDocumentForPart( TSMDocumentID docID)
  43.  
  44.  
  45. Sample Code
  46.  
  47. First,  you need to specify the definition to include the header file in your source code as follows.  The header file is contained in this CD.
  48.  
  49.     #ifdef _OD_SHARETSM_   
  50.     #include "ShareTSM.h"
  51.     #endif
  52.  
  53.        OSErr    err;
  54.           TSMDocument tsmDoc;
  55.        short TSMInterface[] = {kTextService};
  56.        long refcon;
  57.  
  58.           ...
  59.        /* Create a new TSM document */
  60.        err = ODNewTSMDocumentForPart(1, TSMInterface, &tsmDoc, refcon);
  61.     
  62.     ...
  63.     /* Activate the TSM document */
  64.     ODUseTSMDocumentForPart(1, TSMInterface, tsmDoc, refcon);
  65.     ActivateTSMDocument(tsmDoc);
  66.  
  67.     ...
  68.     /* Deactivate the TSM document */
  69.     ODUseTSMDocumentForPart(1, TSMInterface, tsmDoc, refcon);
  70.     DeactivateTSMDocument(tsmDoc);
  71.  
  72.        ...
  73.        /* Delete the TSM document */
  74.        ODUseTSMDocumentForPart(1, TSMInterface, tsmDoc, refcon);
  75.     ODDeleteTSMDocumentForPart(tsmDoc);
  76.  
  77.  
  78. Also the OpenDoc part always checks to see that the API was successfully unresolved at the load time. The following code illustrates how to check this.  The part needs to import this shared libray as ˙weak  import˙ to use the following piece.
  79.  
  80. /* Check the availability of sharing TSM */
  81.     Boolean gValidShareTSMLib;
  82.  
  83.     if ((Ptr)ODNewTSMDocumentForPart == (Ptr)nil)
  84.         gValidShareTSMLib = false;
  85.     else
  86.         gValidShareTSMLib = true;
  87.     
  88. Therefore, OpenDoc parts needs to check the availability of API before calling API.
  89.  
  90.     if (gValidShareTSMLib)
  91.         err = ODNewTSMDocument(1, TSMInterface, &tsmDoc, refcon);
  92.     ...
  93.  
  94.  
  95.  
  96. Additional Info
  97.  
  98. See also TSM support recipe in the folder Documentation:Tech Notes & Articles:Recipes:International.
  99. You can also find the technical notes regarding TSMTE. The TSMTE extension, header files, and sample code are available on the latest Developer CD.